package com.chen.dao;

import com.chen.entity.Project;
import com.chen.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public interface ProjectMapper extends Mapper<Project> {


    @Select("SELECT  t.id AS 'value', t.`pname` AS 'label' FROM `tb_project` t WHERE t.`state` = 1 and t.`create_user_id` = #{uid} ")
    List<HashMap> queryProject(@Param("uid") String uid);

    @Select("SELECT COUNT(1) FROM `tb_project`  t WHERE  t.`pname` = #{pname}  ")
    int queryProjectNumByPname(@Param("pname")String pname);


    //查询风机项目与关联的风机数量
    @Select("SELECT  a.* ,  (SELECT COUNT(1) FROM `tb_fan`  b WHERE  a.`id`  = b.attr_project_id  ) fjnum FROM `tb_project`   a" +
            " where a.create_user_id = #{uid} ")
    List<HashMap> queryProjectAndFansNum(@Param("uid")String uid);

}
